# -*- coding:utf-8 -*-
import json
import pymysql

conn = pymysql.connect(
        host = 'www.qmfang.com',#mysql服务器地址
        port = 3306,#端口号
        user = 'web',#用户名
        passwd = 'qmf20040725',#密码
        db = 'qmfang',#数据库名称
        charset = 'utf8',#连接编码，根据需要填写
    )
cur = conn.cursor()#创建并返回游标

with open("sh_fang_1-33.txt", "r",encoding='utf-8') as f:
    for line in f.readlines():
        line = line.strip('\n')  #去掉列表中每一个元素的换行符
        line = json.loads(line)
        page = line['page']
        name = line['name']
        image = line['image']
        status = line['status']
        type = line['type']
        address = line['address']
        link = line['link']
        area = line['area']
        label = line['label']
        price = line['price']
        sql_insert = "insert into ty_beike_temp (page,name,image,status,type,address,link,area,label,price) values (" + "'" + page + "'" + "," + "'" + name + "'" + "," + "'" + image + "'" + "," + "'" + status + "'" + "," + "'" + type + "'" + "," + "'" + address + "'" + "," + "'" + link + "'" + "," + "'" + area + "'" + "," + "'" + label + "'" + "," + "'" + price + "'" + ");"
        print(sql_insert)
        cur.execute(sql_insert)

conn.commit()
conn.close()